﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace HREntities
{


    public class Company : TaxEntity
    {
        private SortedSet<IPayable> employees;

        public Company(string name, string taxid)
            : this(name, new OrganizationTaxId(taxid))
        { }

        public Company(string name, TaxID taxid)
            : base(name, taxid)
        {
             employees = new SortedSet<IPayable>(new Comparer());
        }

        class Comparer : IComparer<IPayable>
        {
            public int Compare(IPayable x, IPayable y)
            {
                return y.CompareTo(x);
            }
        }
 
        public IEnumerable<IPayable> Employees
        {
            get { return employees; }
        }

        public void Hire(IPayable newHire)
        {
            employees.Add(newHire); 
        }


        public decimal Pay(PayDelegate callback)
        {
            decimal total = 0;
            foreach (IPayable e in Employees)
            {
                decimal net = e.Pay();
                callback(e, net);
                total += net;
            }
            return total;
        }

        public override  decimal Pay()
        {
            decimal total = 0;
            foreach (IPayable e in Employees)
            {
                Console.WriteLine("Now Paying " + e.Name);
                total += e.Pay();
            }
            return total;
        }

    }

   
}
